package mwa.cs.dao;

import java.util.List;
import java.util.Map;

import mwa.cs.database.Database;
import mwa.cs.model.SmMenu;

public class SmMenuDAO {
	private Database db;
	public SmMenuDAO(Database db) {
        this.db = db;
    }
	
	 public void insertSmMenu(SmMenu poSmMenu){
	    	String vaSql = "INSERT INTO sm_menu(menu_id,menu_name,menu_url,menu_parent_id,menu_parent,menu_seq,"
	    			+ "menu_route_previous_id,menu_route_id,menu_route_parent_id,insert_user_id,insert_date,insert_time,"
    			+ "update_user_id,update_date,update_time) "
	    			+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	    	try {
	            db.insert(vaSql,
	            		poSmMenu.getVaMenuId(),
	            		poSmMenu.getVaMenuName(),
	            		poSmMenu.getVaMenuURL(),
	            		poSmMenu.getVaMenuParentId(),
	            		poSmMenu.getVaMenuParent(),
	            		poSmMenu.getVnMenuSeq(),
	            		poSmMenu.getVaMenuRoutePreviousId(),
	            		poSmMenu.getVaMenuRouteId(),
	            		poSmMenu.getVaMenuRouteParentId(),
	            		poSmMenu.getVnInsertUserId(),
	            		poSmMenu.getVaInsertDate(),
	            		poSmMenu.getVaInsertTime(),
	            		poSmMenu.getVnUpdateUserId(),
	            		poSmMenu.getVaUpdateDate(),
	            		poSmMenu.getVaUpdateTime()
	            
	            		);
	        } catch (Exception e) {
	        	e.printStackTrace();
	        	throw new RuntimeException(e);
	        }
	    }
	 public void deleteSmMenu(){
	    	String vaSql = "TRUNCATE TABLE sm_menu ";
	    	try {
	            db.update(vaSql);
	        } catch (Exception e) {
	        	e.printStackTrace();
	        	throw new RuntimeException(e);
	        }
	    }
	 public List<Map<String, Object>> getAllSmMenu() {
	  		String vaSql = "SELECT * FROM sm_menu ORDER BY menu_seq";
	  		List<Map<String, Object>> result = db.queryList(vaSql);
	  		
	  		return result;
	  	}
	 
}
